from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QSlider, QLabel, QComboBox


class BrightnessWidget(QWidget):
    def __init__(self, value=0):
        super().__init__()
        self.value = value
        self.initUI()

    def update_value(self):
        self.value = self.brightness_slider.value()
        self.brightness_level_label.setText(f'Яркость: {self.value}')

    def initUI(self):
        layout = QHBoxLayout()
        self.setLayout(layout)
        self.brightness_level_label = QLabel(f'Яркость: {self.value}')
        self.brightness_slider = QSlider(Qt.Orientation.Horizontal)
        self.brightness_slider.setRange(-100, 100)
        self.brightness_slider.setSingleStep(1)
        self.brightness_slider.setPageStep(10)
        self.brightness_slider.setValue(self.value)
        self.brightness_slider.valueChanged.connect(self.update_value)
        layout.addWidget(self.brightness_level_label)
        layout.addStretch()
        self.brightness_slider.setFixedWidth(self.width() // 2)
        layout.addWidget(self.brightness_slider)


class ContrastWidget(QWidget):
    def __init__(self, value=0):
        super().__init__()
        self.value = value
        self.initUI()

    def update_value(self):
        self.value = self.contrast_slider.value()
        self.contrast_level_label.setText(f'Контраст: {self.value}')

    def initUI(self):
        layout = QHBoxLayout()
        self.setLayout(layout)
        self.contrast_level_label = QLabel(f'Контраст: {self.value}')
        self.contrast_slider = QSlider(Qt.Orientation.Horizontal)
        self.contrast_slider.setRange(-100, 100)
        self.contrast_slider.setSingleStep(1)
        self.contrast_slider.setPageStep(10)
        self.contrast_slider.setValue(self.value)
        self.contrast_slider.valueChanged.connect(self.update_value)
        layout.addWidget(self.contrast_level_label)
        layout.addStretch()
        self.contrast_slider.setFixedWidth(self.width() // 2)
        layout.addWidget(self.contrast_slider)


class SourceWidget(QWidget):
    def __init__(self, string=""):
        super().__init__()
        self.sources = string.lstrip('--source').split('[')[0].strip().split('|')
        self.default_source = string.split('[')[-1].split(']')[0].strip()
        self.initUI()

    def initUI(self):
        layout = QHBoxLayout()
        self.setLayout(layout)
        self.source_level_label = QLabel(f'Источник: ')
        self.source_combobox = QComboBox()
        self.source_combobox.addItems(self.sources)
        try:
            self.source_combobox.setCurrentText(self.default_source)
        except Exception:
            pass
        layout.addWidget(self.source_level_label)
        layout.addStretch()
        self.source_combobox.setFixedWidth(self.width() // 2)
        layout.addWidget(self.source_combobox)


class ResolutionWidget(QWidget):
    def __init__(self, string=""):
        super().__init__()
        self.resolutions = string.lstrip('--resolution').split('[')[0].strip().split('|')
        self.default_resolution = string.split('[')[-1].split(']')[0].strip()
        self.initUI()

    def initUI(self):
        layout = QHBoxLayout()
        self.setLayout(layout)
        self.resolution_level_label = QLabel(f'Разрешение: ')
        self.resolution_combobox = QComboBox()
        self.resolution_combobox.addItems(self.resolutions)
        try:
            self.resolution_combobox.setCurrentText(self.default_resolution)
        except Exception:
            pass
        layout.addWidget(self.resolution_level_label)
        layout.addStretch()
        self.resolution_combobox.setFixedWidth(self.width() // 2)
        layout.addWidget(self.resolution_combobox)

